from typing import Sequence
from schedule.PowerSchedule import PowerSchedule
from utils.Seed import Seed


class CoveragePowerSchedule(PowerSchedule):
    def __init__(self, exponent: float = 1.0) -> None:
        super().__init__()
        self.exponent = exponent

    def assign_energy(self, population: Sequence[Seed]) -> None:
        """
        Assign energy based on the number of coverage points
        """
        total_coverage = [len(seed.coverage) for seed in population]

        for seed in population:
            cov = len(seed.coverage)
            # 加1防止0除法，指数调节力度
            seed.energy = (cov + 1) ** self.exponent
